package com.hanggold.jfinal.controller;

import com.hanggold.jfinal.model.UserInfo;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.Date;

/**
 * TODO COMMENT.
 *
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-06-29 08:43
 * @since 1.0.0
 **/
@Path("model")
public class ModelController extends Controller {
    
    public void save() {
        boolean save = new UserInfo().set("username", "helloworld").set("birthday", new Date()).set("code", 22).save();
        renderText(String.format("保存用户成功与否: %s ", save));
    }
    
    public void update() {
        
        UserInfo.dao.findById(1).set("username", "updateHelloWorld").update();
        renderText("update success");
        
    }
    
    public void query() {
        UserInfo userInfo = UserInfo.dao.findById(1);
        renderText(userInfo.toString());
    }
    
    public void queryColumn() {
        UserInfo userInfo = UserInfo.dao.findByIdLoadColumns(1, "id,username,birthday");
        renderText(userInfo.toString());
    }
    
    
    public void record(){
        Record record = Db.findById("user_info", 1);
        Object id = record.get("id");
        renderText("record");
        
    }
    
}
